<template>
  <div class="page-hero" v-if="model">
    <div class="topbar bg-black py-2 px-3 d-flex ai-center text-white">
      <img src="../assets/logo.png" height="30" alt="" />
      <div class="px-2 flex-1">
        <span class="text-white">王者荣耀</span>
        <span class="ml-2">攻略站</span>
      </div>
      <router-link tag="div" to="/">更多英雄 &gt;</router-link>
    </div>
    <div class="top" :style="{ 'background-image': `url(${model.banner})` }">
      <div class="info text-white p-3 h-100 d-flex flex-column jc-end">
        <div class="fs-sm">{{ model.title }}</div>
        <h2 class="my-2">{{ model.name }}</h2>
        <div class="fs-sm">
          {{ model.categories.map((v) => v.name).join("/") }}
        </div>
        <div class="d-flex jc-between ai-center py-1">
          <div class="scores d-flex ai-center" v-if="model.scores">
            <span>难度</span>
            <span class="badge bg-primary">{{ model.scores.defficult }}</span>
            <span>技能</span>
            <span class="badge bg-blue-1">{{ model.scores.skills }}</span>
            <span>攻击</span>
            <span class="badge bg-danger">{{ model.scores.attack }}</span>
            <span>生存</span>
            <span class="badge bg-dark-2">{{ model.scores.survive }}</span>
          </div>
          <router-link to="/" tag="span" class="fs-sm text-grey"
            >皮肤：2 &gt;</router-link
          >
        </div>
      </div>
    </div>
    <!-- end of top -->
    <div>
      <div class="bg-white px-3">
        <div class="nav d-flex jc-around pt-3 pb-2 border-bottom">
          <div class="nav-item active">
            <div class="nav-link">英雄初识</div>
          </div>
          <div class="nav-item">
            <div class="nav-link">进阶攻略</div>
          </div>
        </div>
      </div>

      <swiper>
        <swiper-slide>
          <div>
            <!-- 技能模块 start -->
            <div class="p-3 bg-white border-bottom">
              <!-- button 部分 -->
              <div class="d-flex">
                <router-link to="/" tag="button" class="btn btn-lg flex-1">
                  <i class="iconfont icon-menu"></i>
                  英雄介绍视频
                </router-link>
                <router-link to="/" tag="button" class="btn btn-lg flex-1 ml-2">
                  <i class="iconfont icon-menu"></i>
                  一图识英雄
                </router-link>
              </div>
              <!-- skills 部分 -->
              <div class="skills mt-3">
                <!-- skill icon start -->
                <div class="d-flex jc-around">
                  <img
                    class="icon"
                    :class="{ active: currentSkillIndex === i }"
                    @click="currentSkillIndex = i"
                    :src="item.icon"
                    v-for="(item, i) in model.skills"
                    :key="i"
                    :alt="item.name"
                  />
                </div>
                <!-- skill icon end -->
                <!-- skill description start -->
                <div v-if="currentSkill">
                  <div class="d-flex ai-center pt-4 pb-3">
                    <h3 class="m-0">{{ currentSkill.name }}</h3>
                    <span class="text-grey ml-4 fs-sm"
                      >(冷却值: {{ currentSkill.delay }}消耗值:
                      {{ currentSkill.cost }})</span
                    >
                  </div>
                  <p>{{ currentSkill.description }}</p>
                  <div class="border-bottom"></div>
                  <p class="text-grey fs-sm">小提示: {{ currentSkill.tips }}</p>
                </div>
                <!-- skill description end -->
              </div>
            </div>
            <!-- 技能模块 end -->
            <m-card plain icon="menu" title="出装推荐" class="hero-items">
              <div class="border-bottom">
                <div class="fs-xl">顺风出装</div>
                <div class="d-flex jc-around text-center mt-3">
                  <div v-for="item in model.items1" :key="item._id">
                    <img :src="item.icon" :alt="item.name" class="icon" />
                    <div class="fs-xxs mt-1">{{ item.name }}</div>
                  </div>
                </div>
              </div>
              <div class="mt-3">
                <div class="fs-xl">逆风出装</div>
                <div class="d-flex jc-around text-center mt-3">
                  <div v-for="item in model.items2" :key="item._id">
                    <img :src="item.icon" :alt="item.name" class="icon" />
                    <div class="fs-xxs mt-1">{{ item.name }}</div>
                  </div>
                </div>
              </div>
            </m-card>

            <m-card plain icon="menu" title="使用技巧">
              <p class="m-0">{{ model.usageTips }}</p>
            </m-card>
            <m-card plain icon="menu" title="对抗技巧">
              <p class="m-0">{{ model.battleTips }}</p>
            </m-card>
            <m-card plain icon="menu" title="团战思路">
              <p class="m-0">{{ model.teamTips }}</p>
            </m-card>
            <m-card plain icon="menu" title="英雄关系">
              <div class="border-bottom pb-3">
                <div class="fs-xl">最佳搭档</div>
                <div
                  class="d-flex pt-3"
                  v-for="item in model.partners"
                  :key="item._id"
                >
                  <img :src="item.hero.avatar" alt="" height="46.5" />
                  <p class="flex-1 m-0 ml-3">{{ item.description }}</p>
                </div>
              </div>
              <div class="border-bottom pb-3 mt-3">
                <div class="fs-xl">被谁克制</div>
                <div
                  class="d-flex pt-3"
                  v-for="item in model.partners"
                  :key="item._id"
                >
                  <img :src="item.hero.avatar" alt="" height="46.5" />
                  <p class="flex-1 m-0 ml-3">{{ item.description }}</p>
                </div>
              </div>
            </m-card>
          </div>
        </swiper-slide>
      </swiper>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    id: { required: true },
  },
  data() {
    return {
      model: null,
      currentSkillIndex: 0,
    };
  },
  methods: {
    async fetch() {
      const res = await this.$http.get(`heroes/${this.id}`);
      this.model = res.data;
    },
  },
  computed: {
    currentSkill() {
      return this.model.skills[this.currentSkillIndex];
    },
  },
  created() {
    this.fetch();
  },
};
</script>

<style lang="scss">
@import "../assets/scss/variables";
.page-hero {
  .top {
    height: 50vw;
    background: #fff no-repeat top center;
    background-size: auto 100%;

    .info {
      background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 1));
      .scores {
        .badge {
          display: inline-block;
          margin: 0 0.25rem;
          width: 1rem;
          height: 1rem;
          text-align: center;
          line-height: 0.9rem;
          font-size: 0.1rem;
          border-radius: 50%;
          border: 1px solid rgba(255, 255, 255, 0.2);
        }
      }
    }
  }

  .skills {
    img.icon {
      width: 65px;
      height: 65px;
      border: 2px solid map-get($colors, "white");
      border-radius: 45%;
      &.active {
        border-color: map-get($colors, "primary");
      }
    }
  }

  .hero-items {
    img.icon {
      width: 3.5769rem;
      height: 3.5769rem;
      border-radius: 50%;
    }
  }
}
</style>
